﻿using zijian666.WorkScheduler.Abstractions;

namespace zijian666.WorkScheduler.Defines;

/// <summary>
/// 表示一个工作实体。
/// </summary>
public readonly record struct WorkData : IEquatable<WorkData>
{
    /// <summary>
    /// 获取工作标识。
    /// </summary>
    public required string Id { get; init; }
    /// <summary>
    /// 获取工作组。
    /// </summary>
    public required IWorkGroup Group { get; init; }

    private readonly WorkStatus _status;
    /// <summary>
    /// 获取工作状态。
    /// </summary>
    public required WorkStatus Status
    {
        get => IsEmpty ? WorkStatus.Missing : _status;
        init => _status = value;
    }


    private readonly DateTimeOffset _planTime;
    /// <summary>
    /// 获取工作计划时间。
    /// </summary>
    public required DateTimeOffset PlanTime
    {
        get => IsEmpty ? DateTimeOffset.MaxValue : _planTime;
        init => _planTime = value;
    }
    /// <summary>
    /// 工作凭证
    /// </summary>
    public string? Ticket { get; init; }

    /// <summary>
    /// 获取工作参数。
    /// </summary>
    public object? Arguments { get; init; }

    /// <summary>
    /// 是否为空对象
    /// </summary>
    public bool IsEmpty
        => string.IsNullOrWhiteSpace(Id) || _status is WorkStatus.Missing || Group is null;

    /// <inheritdoc />
    public override int GetHashCode()
    {
        return base.GetHashCode();
    }

    bool IEquatable<WorkData>.Equals(WorkData other)
        => IsEmpty ? false : Id == other.Id;

}

